package cn.com.bdqn.dao;

import cn.com.bdqn.entity.SysMenu;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SysMenuDao {

    @Select("select m.*\n" +
            "from sys_role_right a,sys_menu m\n" +
            "where a.rf_right_code = m.menu_code \n" +
            "and rf_role_id = #{usrRoleId} and menu_parent_code = #{menuParentCode};")
    public List<SysMenu> queryMenuByRoleId(@Param("usrRoleId") Long usrRoleId,@Param("menuParentCode") Long menuParentCode);

    @Select("select * ,(select true from sys_role_right where rf_right_code = menu_code and rf_role_id = #{rfRoleId}) isck\n" +
            "from sys_menu where menu_parent_code = #{menuParentCode}")
    public List<SysMenu> queryAll(@Param("rfRoleId") Long rfRoleId,@Param("menuParentCode") Long menuParentCode);

    public List<SysMenu> queryByLike(SysMenu sysMenu);

    @Select("select * from sys_menu where  menu_code = #{value}")
    public SysMenu queryByMenuCode(Long menuCode);

    public int updateSysMenu(SysMenu sysMenu);

    @Select("select * from sys_menu where menu_parent_code = 0")
    public List<SysMenu> queryParent();

    @Insert("insert into sys_menu values\n" +
            "(default,#{menuParentCode},#{menuType},#{menuText},#{menuUrl},#{menuTip})")
    public int addSysMenu(SysMenu sysMenu);
}
